<?php
/**
 * Created by PhpStorm.
 * User: jsq
 * Date: 2017/5/3 0003
 * Time: 14:05
 */
namespace app\admin\controller;
use app\common\model\Leibie as leib;
use think\Request;
use think\Facade\Session;
use app\common\traits\Page;

class Leibei extends Admin
{
    use Page;
    public function index(Request $request)
    {
        $order = new leib();
        $map = $request->param();
        $this->assign('form',$map);
        $data = $order->map($map);
        $list   = $this->pageshow('leibie',$data);
        $leibie = $order->getleibei();
        $this->assign('leibie',$leibie);

        $this->assign('list',$list);
        return $this->fetch('index');
    }

    public function add(Request $request){
        $leib = new leib();
        if($request->isPost()) {
            $data = $request->param();
            $data['status'] = 1;
            $data['createtime'] = time();
            $resul = $leib->edit($data);
            return $resul;
        }else{
            $leibie = $leib->getleibei();
            $this->assign('leibie',$leibie);
            $diqu  =  $leib->getArea();
            $this->assign('diqu',$diqu);
            return $this->fetch('add');
        }
    }

    public function cat(Request $request){
        $leib = new leib();
        $id = $request->param('id');
        $info   =  $leib->where('id',$id)->find();
        $this->assign('info',$info);
        $leibie = $leib->getleibei();
        $this->assign('leibie',$leibie);
        return $this->fetch();
    }

    public function edit(Request $request){
        $leib = new leib();
        $id = $request->param('id');
        if($this->request->isPost()) {
            $data = $request->param();
            $data['edittime'] = time();
            $resul = $leib->edit($data);
            return $resul;
        }else{
            $info   =  $leib->where('id',$id)->find();
            $this->assign('info',$info);
            $leibie = $leib->getleibei();
            $this->assign('leibie',$leibie);
            $diqu  =  $leib->getArea();
            $this->assign('diqu',$diqu);
            return $this->fetch('edit');
        }
    }

    /**  查看订单详细
     * @return mixed
     */
    /* 删除 */
    public function del(Request $request)
    {
        $id   = $request->param('id');
        $leib = new leib();
        $data['id']    = $id;
        $data['status'] = 0;   //逻辑删除  设为禁用
        $re = $leib->isUpdate()->save($data);
        if($re){
            return ['status'=>1,'msg'=>"删除订单数据成功！"];
        }else{
            return ['status'=>0,'msg'=>"删除数据失败！"];
        }
    }

}